﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataBatchCompilations" @search="getTableDataBatchCompilations">
      <el-row>
        
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="factoryCode_FormItem" prop="factoryCode" label="工厂编码">
            <el-input v-model="searchDataBatchCompilations.factoryCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="lineCode_FormItem" prop="lineCode" label="产线编码">
            <el-input v-model="searchDataBatchCompilations.lineCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="stationCode_FormItem" prop="stationCode" label="工位编码">
            <el-input v-model="searchDataBatchCompilations.stationCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="orderCode_FormItem" prop="orderCode" label="所属工单">
            <el-input v-model="searchDataBatchCompilations.orderCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="scheduleCode_FormItem" prop="scheduleCode" label="所属排程">
            <el-input v-model="searchDataBatchCompilations.scheduleCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="materialCode_FormItem" prop="materialCode" label="物料编码">
            <el-input v-model="searchDataBatchCompilations.materialCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="materialName_FormItem" prop="materialName" label="物料名称">
            <el-input v-model="searchDataBatchCompilations.materialName" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="batchCode_FormItem" prop="batchCode" label="批次号">
            <el-input v-model="searchDataBatchCompilations.batchCode" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="batchSingleCostQty_FormItem" prop="batchSingleCostQty" label="批次料单次消耗量">
            <el-input v-model="searchDataBatchCompilations.batchSingleCostQty" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="isUse_FormItem" prop="isUse" label="是否启用">
            <el-select v-model="searchDataBatchCompilations.isUse" clearable>
                <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
                <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
                </el-select>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Filed1_FormItem" prop="Filed1" label="预留域1">
            <el-input v-model="searchDataBatchCompilations.Filed1" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Filed2_FormItem" prop="Filed2" label="预留域2">
            <el-input v-model="searchDataBatchCompilations.Filed2" clearable></el-input>
        </el-form-item>
    </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
    <WtmButton  type="primary" button-text="黑名单管理" @click="BLShowModal=true"></WtmButton>
      <WtmButton v-auth="'/api/BatchCompilations/Add'" icon='fa fa-plus' type='primary' :button-text="$t('message._system.common.vm.add')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/BatchCompilations/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message._system.common.vm.batchdelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/BatchCompilations/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message._system.common.vm.import')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/BatchCompilations/ExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message._system.common.vm.export')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefBatchCompilations" v-bind="tableDataBatchCompilations">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
          
          <el-button text type="primary" @click="OnEditrowClick(scope.row)" v-auth="'/api/BatchCompilations/Edit'">{{ $t('message._system.common.vm.edit') }}</el-button>
					<el-button text type="primary" @click="OnDetailsrowClick(scope.row)" v-auth="'/api/BatchCompilations/{id}'">{{ $t('message._system.common.vm.detail') }}</el-button>
					<el-popconfirm :title="$t('message._system.common.vm.deletetip')"  @confirm="onDelete(scope.row)">
						<template #reference>
							<el-button text type="danger" v-auth="'/api/BatchCompilations/BatchDelete'">{{ $t('message._system.common.vm.delete') }}</el-button>
						</template>
					</el-popconfirm>
                    <el-popconfirm :title="$t('message._system.common.vm.deletetip')"  @confirm="AddBlackList(scope.row)">
						<template #reference>
							<el-button text type="danger">加入黑名单</el-button>
						</template>
					</el-popconfirm>
        </template>
      </el-table-column>
    </template>
  </WtmTable>
<el-dialog v-model="BLShowModal" title="黑名单管理" width="60%" center>
 <el-table :data="BlackList" style="width: 100%">
    <el-table-column label="供应商代码">
        <template #default="{ row, $index }">
            <el-input v-model="row.supplementCode" enable="false"></el-input>
        </template>
    </el-table-column>
    <el-table-column label="物料编码">
        <template #default="{ row, $index }">
            <el-input v-model="row.materialCode" enable="false"></el-input>
        </template>
    </el-table-column>
    <el-table-column label="物料名称">
        <template #default="{ row, $index }">
            <el-input v-model="row.materialName" enable="false"></el-input>
        </template>
    </el-table-column>
    <el-table-column label="更新时间">
        <template #default="{ row, $index }">
            <el-input v-model="row.CreateTime" enable="false"></el-input>
        </template>
    </el-table-column>
    <el-table-column label="操作" width="180">
        <template #default="{row, $index }">
            <el-popconfirm title="确定移除黑名单吗？" @confirm="RemoveBlacklistOfBatch(row)">
                <template #reference>
                    <el-button type="danger">移除</el-button>
                </template>
            </el-popconfirm>
        </template>
    </el-table-column>
 </el-table>
</el-dialog>
</el-card>
</div>


</template>


<script setup lang="ts" name="批次基础信息管理;true;TyMES.Controllers;BatchCompilations">
import {  ElMessageBox, ElMessage } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { BatchCompilationsApi } from '/@/api/baseinformation/BatchCompilations';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;
import request from '/@/utils/request';

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateBatchCompilations = reactive({
    
});

const searchDataBatchCompilations = ref({
    			factoryCode: null,
			lineCode: null,
			stationCode: null,
			orderCode: null,
			scheduleCode: null,
			materialCode: null,
			materialName: null,
			batchCode: null,
			batchSingleCostQty: null,
			isUse: null,
			Filed1: null,
			Filed2: null,

});

// 定义变量内容
const tableRefBatchCompilations = ref();
const tableDataBatchCompilations = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
  
        {title:'工厂编码',key: 'factoryCode',type: 'text',isCheck: true},
        {title:'产线编码',key: 'lineCode',type: 'text',isCheck: true},
        {title:'工位编码',key: 'stationCode',type: 'text',isCheck: true},
        {title:'所属工单',key: 'orderCode',type: 'text',isCheck: true},
        {title:'所属排程',key: 'scheduleCode',type: 'text',isCheck: true},
        {title:'物料编码',key: 'materialCode',type: 'text',isCheck: true},
        {title:'物料名称',key: 'materialName',type: 'text',isCheck: true},
        {title:'批次号',key: 'batchCode',type: 'text',isCheck: true},
        {title:'批次料单次消耗量',key: 'batchSingleCostQty',type: 'text',isCheck: true},
        {title:'批次料添加量',key: 'batchAddQty',type: 'text',isCheck: true},
        {title:'批次料余量',key: 'batchMarginQty',type: 'text',isCheck: true},
        {title:'是否启用',key: 'isUse',type: 'switch',isCheck: true},
        {title:'预留域1',key: 'Filed1',type: 'text',isCheck: true},
        {title:'预留域2',key: 'Filed2',type: 'text',isCheck: true},
	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataBatchCompilations = () => {
    tableRefBatchCompilations.value.doSearch(BatchCompilationsApi().search, searchDataBatchCompilations.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.add'), CreateDialog, null, getTableDataBatchCompilations)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.edit'), EditDialog, row, getTableDataBatchCompilations)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.detail'), DetailsDialog, row, getTableDataBatchCompilations)
};

// 删除
const onDelete = (row: any) => {
    BatchCompilationsApi().delete([row.ID]).then(() => { getTableDataBatchCompilations()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefBatchCompilations.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      BatchCompilationsApi().delete(selectedids).then(() => { getTableDataBatchCompilations()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.import'), ImportDialog, null, getTableDataBatchCompilations)
};

const onExport = () => {
	const selected = tableRefBatchCompilations.value.getSelectedRows();
	if (selected.length > 0) {
		BatchCompilationsApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		BatchCompilationsApi().export(searchDataBatchCompilations.value);
	}
};

//#region  批次物料黑名单管理
const BLShowModal = ref(false);
const BlackList = ref([]);

const GetBlacklistOfBatch = ()=>{
    request({
            url: 'api/BatchCompilations/SearchBlacklist',
            method: 'post',
            data:{
                'stationCode':'',
            },
        }).then(
            res => {
                console.log('ss',res),
                BlackList.value =  res,
                console.log('s2',res)
        });
}

const RemoveBlacklistOfBatch = (row:any)=>{
    request({
            url: 'api/BatchCompilations/RemoveFormBlacklist',
            method: 'post',
            data:row,
        }).then(
            res => {
            if (res.Success) 
            {
                ElMessage.success(res.Mesg);
                GetBlacklistOfBatch();
            }
            else {
                ElMessage.error(res.Mesg);
            }
        });
}

const AddBlackList = (row: any) =>{
    //console.log('ss',row);
    request({
            url: 'api/BatchCompilations/AddBlacklist',
            method: 'post',
            data:row,
        }).then(
            res => {
            if (res.Success) {
                ElMessage.success(res.Mesg);
                GetBlacklistOfBatch();
            }
            else {
                ElMessage.error(res.Mesg);
            }
        });
    
    //console.log('qx',showModal.value);
}

//#endregion

// 页面加载时
onMounted(() => {
        GetBlacklistOfBatch();
        getTableDataBatchCompilations();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

